<?php

namespace App\Admin\Controllers;

use App\Models\Mint;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class MintController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(Mint::with(['user']), function (Grid $grid) {
            $grid->model()->orderByDesc('id');
            $grid->column('id')->sortable();
            $grid->column('user_id');
            $grid->column('user.address', '用户地址')->width('120px')->style('word-wrap: break-word;word-break: break-all;white-space: normal;');
            $grid->column('nft_id')->width('120px')->style('word-wrap: break-word;word-break: break-all;white-space: normal;');
            $grid->column('power');
            $grid->column('per_mint');
            $grid->column('amount');
            $grid->column('fee');
            $grid->column('to_amount');
            $grid->column('hash');
            $grid->column('status');
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('user_id');
                $filter->equal('user.address', '用户地址');
                $filter->equal('nft_id');
                $filter->equal('hash');
            });
            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->disableBatchActions();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Mint(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('nft_id');
            $show->field('power');
            $show->field('per_mint');
            $show->field('amount');
            $show->field('fee');
            $show->field('to_amount');
            $show->field('hash');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Mint(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('nft_id');
            $form->text('power');
            $form->text('per_mint');
            $form->text('amount');
            $form->text('fee');
            $form->text('to_amount');
            $form->text('hash');
            $form->text('status');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
